/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mii.dao.impl;

import java.util.List;
import javax.persistence.EntityManager;
import mii.dao.CustomerDAO;
import mii.ejb.entity.Customer;

/**
 *
 * @author TEKNISI
 */
public class CustomerDAOImpl implements CustomerDAO {
private EntityManager em;
    
    public CustomerDAOImpl(EntityManager em){
        this.em = em;
    }
    @Override
    public void insert(Customer customer) throws Exception {
        this.em.persist(customer); }

    @Override
    public void update(Customer customer) throws Exception {
       this.em.merge(customer);  }

    @Override
    public void delete(Customer customer) throws Exception {
       this.em.remove(customer);  }

    @Override
    public Customer getById(long id) throws Exception {
        return this.em.find(Customer.class, id);
   }

    @Override
    public List<Customer> getAll() throws Exception {
        return this.em.createQuery("SELECT d FROM Customer d").getResultList();
    }

    @Override
    public Customer getByKode(String kodeCust) throws Exception {
         return this.em.find(Customer.class, kodeCust);
   }
    
}
